package com.example.administrator.customview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private ImageView level1;
    private ImageView level2;
    private ImageView level3;

    //判断三是否显示
    boolean islevel3Show = true;
    boolean islevel2Show = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        level1 = findViewById(R.id.level1);
        level2 = findViewById(R.id.level2);
        level3 = findViewById(R.id.level3);

        initListener();
    }

    private void initListener() {

        level2.setOnClickListener(this);
        level1.setOnClickListener(this);
        level3.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.level1:
                if(islevel2Show){
                    RotateUtils.viewRotate(level2, 0, 180,1000);
                    RotateUtils.viewRotate(level3, 0, 180,1500);
                    islevel2Show=false;
                }else {
                    RotateUtils.viewRotate(level2, 180, 360,1000);
                    RotateUtils.viewRotate(level3, 180, 360,1500);
                    islevel2Show=true;
                }
                break;
            case R.id.level2:
                //嘴歪一层旋转0--180；
                if (islevel3Show) {
                    RotateUtils.viewRotate(level3, 0, 180,1000);
                    islevel3Show = false;
                } else {
                    RotateUtils.viewRotate(level3, 180, 360,1000);
                    islevel3Show = true;
                }
                break;
            case R.id.level3:
                Toast.makeText(MainActivity.this, "我是三", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
